package com.zdwhong.mysqlms.controller;

import com.zdwhong.mysqlms.entity.User;
import com.zdwhong.mysqlms.mapper.UserMapper;
import com.zdwhong.mysqlms.multidatasource.Master;
import com.zdwhong.mysqlms.multidatasource.Slave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZDW
 * @since 2021-05-26 9:53
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Slave
    @GetMapping("list")
    public List<User> userList() {
        List<User> userList = userMapper.selectList(null);

        return userList;
    }

    @Master
    @PostMapping("insert")
    public int insertUser(@RequestBody User user) {
        int insert = userMapper.insert(user);
        return insert;
    }
}
